// pages/xunJianDetails/xunJianDetails.js
const httpRequest = require('../../utils/http_utils.js')
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title:'',
    showNormal:false, //判断巡检结果是否异常
    showAbnormal: false,
    stateValue:false,
    Prohibit:true, //判断单选是否启用
    Submission:false, //判断详情和新增
    TaskType:'', //设备、设备间类型
    RowGuid:'', //设备ID
    InspectionList:[], //详情集合
    TaskRemark:'', //备注
    enclosureList:[], //附件集合
    UploadUrl: httpRequest.uploadUrl,
    height: 60, //高度
    customHeight: 0, //自定义高度
  },

  inputInfo:function(e){
    console.log(JSON.stringify(e))
  },

  initData:function(){
    var that = this;
    var param = {
      TaskType: that.data.TaskType,
      TaskGuid: that.data.RowGuid
    }
    console.log(JSON.stringify(param)+"-------------接口参数")
    httpRequest.GetValidateRequest(httpRequest.apiInfo.GetFinishInspectTaskDetailApi, param, function (data) {
      console.log(JSON.stringify(data) + "--------------接口数据")
      var listData = that.data.InspectionList;
      if (data.PageData.length <= 0 || data.PageData == null || data.PageData == [] || data.PageData == undefined) {

      } else {
        for (var i = 0; i < data.PageData.length; i++) {
          var CollectionValues = data.PageData[i].CollectionValue;
          if (CollectionValues == null || CollectionValues == undefined){
            CollectionValues = '';
          }
          var params={
            SpotName: data.PageData[i].SpotName,
            CollectionValue: CollectionValues
          }
          listData.push(params)
        }
        that.setData({
          InspectionList: listData
        })
      }
      var listArray = that.data.enclosureList;
      if (data.FileInfo.length <= 0 || data.FileInfo == null || data.FileInfo == [] || data.FileInfo == undefined){
        return;
      }else{
        console.log(data.FileInfo.length + "---------附件长度")
        if (data.FileInfo.length <= 0) {
          that.setData({
            height: 60
          })
        } else if (data.FileInfo.length > 4){
          that.setData({
            height: 400
          })
        } else {
          that.setData({
            height: 220
          })
        }
        for (var i = 0; i < data.FileInfo.length; i++){
          listArray.push(data.FileInfo[i])
        }
        that.setData({
          enclosureList: listArray
        })
        console.log(JSON.stringify(that.data.enclosureList) +"---------附件")
      }
    }, function (err) { })
  },

  //预览图片
  previewImg: function (e) {
    console.log(e)
    let imglist = e.currentTarget.dataset.imglist
    let index = e.currentTarget.dataset.index;
    let imgs = [];
    console.log(imglist)
    for (var i = 0; i < imglist.length; i++) {
      imgs.push(this.data.UploadUrl + imglist[i].FilePath)
    }
    console.log(imgs)
    wx.previewImage({
      current: imgs[index],
      urls: imgs,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.setData({
      customHeight: (app.globalData.titleBarHeight + app.globalData.statusBarHeight) * 2
    })

    console.log(JSON.stringify(options) + "------------接收")
    if (options.TaskType == "1" || options.TaskType == 1){
      this.setData({
        TaskType:"0"
      })
    } else if (options.TaskType == "2" || options.TaskType == 2){
      this.setData({
        TaskType: "1"
      })
    }
    if (options.TaskRemark == "null" || options.TaskRemark == undefined || options.TaskRemark == null){
      this.setData({
        TaskRemark: ""
      })
    }else{
      this.setData({
        TaskRemark: options.TaskRemark
      })
    }
    this.setData({
      title: options.RoomName,
      RowGuid: options.RowGuid,
    })
    this.initData();
    if (options.IsAlarm == 0){
      this.setData({
        showNormal: true,
        showAbnormal: false
      })
    } else if (options.IsAlarm == 1){
      this.setData({
        showNormal: false,
        showAbnormal: true
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})